package com.xl.rentkeeper.act.jilu;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xl.fuse.protos.viewroom.RoomInfo;
import com.xl.fuse.protos.viewroom.ViewOrderStatus;
import com.xl.rentkeeper.App;
import com.xl.rentkeeper.R;
import com.xl.rentkeeper.act.BaseAct;
import com.xl.rentkeeper.entity.Order;
import com.xl.rentkeeper.log.QLog;
import com.xl.rentkeeper.util.Util;
import com.xl.rentkeeper.view.TitleBar;

/**
 * Created by Administrator on 2015/8/17.
 */
public class NotSignDetailAct extends BaseAct implements View.OnClickListener {
    private Order mOrder;
    private String mTitle;

    private TextView mTVName;
    private TextView mTVTime;
    private TextView mTVJob;
    private TextView mTVPrice;//金额
    private TextView mTVCheckin;//入住时间
    private TextView mTVRoomName1;//房间信息
    private TextView mTVRoomPrice1;//房间价格
    private TextView mTVRoomName2;//房间信息
    private TextView mTVRoomPrice2;//房间价格
    private TextView mTVRemark;//房间价格
    private TextView mTVLBRemark;//房间价格

    private LinearLayout mLLRoomInfo1;
    private LinearLayout mLLRoomInfo2;
    private TextView mTVCall;
    private TitleBar tb;
    private TextView mTVNotSignRemark;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_not_signed_detail);
        tb = (TitleBar) findViewById(R.id.tb);
        setTranslucentStatus();
        mOrder = (Order) getIntent().getSerializableExtra("msg");
        QLog.d("TAG", mOrder.viewOrder.toString());
        mTitle = getIntent().getStringExtra("title");
        tb.setTitleName(mTitle);
        initTitleBar(tb);
        initView();
        initData();
    }

    private void initView() {
        mTVName = (TextView) findViewById(R.id.tv_name);
        mTVTime = (TextView) findViewById(R.id.tv_orderTime);
        mTVPrice = (TextView) findViewById(R.id.tv_expect_price);
        mTVRoomName1 = (TextView) findViewById(R.id.tv_roomName1);
        mTVRoomName2 = (TextView) findViewById(R.id.tv_roomName2);
        mTVRoomPrice1 = (TextView) findViewById(R.id.tv_roomPrice1);
        mTVRoomPrice2 = (TextView) findViewById(R.id.tv_roomPrice2);
        mTVRemark = (TextView) findViewById(R.id.tv_remark);
        mLLRoomInfo1 = (LinearLayout) findViewById(R.id.ll_roomInfo1);
        mLLRoomInfo2 = (LinearLayout) findViewById(R.id.ll_roomInfo2);
        mTVJob = (TextView) findViewById(R.id.tv_job);
        mTVCheckin = (TextView) findViewById(R.id.tv_checkInDay);

        mTVLBRemark = (TextView) findViewById(R.id.tv_lbremark);
        mTVNotSignRemark = (TextView) findViewById(R.id.tv_notsign_remark);

        mTVCall = (TextView) findViewById(R.id.tv_phone);
        mTVCall.setOnClickListener(this);

    }

    private void initData() {
        Intent intent = this.getIntent();
        mOrder = (Order) intent.getSerializableExtra("msg");

        mTVName.setText(mOrder.viewOrder.name);
        mTVTime.setText(Util.replaceTimeNull(mOrder.viewOrder.viewTime));
        Util.setExpectPrice(mTVPrice, mOrder.viewOrder, "not_sign_detail");
        mTVJob.setText(Util.replaceNull(null, mOrder.viewOrder.job));
        mTVCheckin.setText(Util.replaceNull(null, mOrder.viewOrder.checkInDays));
        mTVRemark.setText(Util.replaceNull(null, mOrder.viewOrder.remark));

        if (mOrder.viewOrder.status == ViewOrderStatus.ORDER_NOT_SIGN.getValue()) {
            tb.setTitleName("未签约订单");
            mTVLBRemark.setText("未签约理由");
            mTVNotSignRemark.setText(Util.replaceNull(null, mOrder.viewOrder.unSignRemark));
        } else if (mOrder.viewOrder.status == ViewOrderStatus.ORDER_NOT_VIEW.getValue()) {
            tb.setTitleName("未看房订单");
            mTVLBRemark.setText("未看房理由");
            mTVNotSignRemark.setText(Util.replaceNull(null, mOrder.viewOrder.unViewRemark));
        }
        if (mOrder.viewOrder.viewRooms == null || mOrder.viewOrder.viewRooms.size() == 0) {
            mLLRoomInfo2.setVisibility(View.GONE);
            mLLRoomInfo1.setVisibility(View.GONE);
        } else {
            if (mOrder.viewOrder.viewRooms.size() == 1) {//只有一个房间
                mLLRoomInfo2.setVisibility(View.GONE);
                RoomInfo rInfo = mOrder.viewOrder.viewRooms.get(0);
                if (TextUtils.isEmpty(rInfo.name)) {
                    mTVRoomName1.setText("无");
                } else {
                    mTVRoomName1.setText(rInfo.name);
                    Util.setRoomStatus(mTVRoomPrice1, rInfo, "not_sign_detail");
                }
            } else {//两个房间
                RoomInfo rInfo = mOrder.viewOrder.viewRooms.get(0);
                if (TextUtils.isEmpty(rInfo.name)) {
                    mTVRoomName1.setText("无");
                } else {
                    mTVRoomName1.setText(rInfo.name);
                    Util.setRoomStatus(mTVRoomPrice1, rInfo, "not_sign_detail");
                }
                RoomInfo rInfo2 = mOrder.viewOrder.viewRooms.get(1);
                if (TextUtils.isEmpty(rInfo2.name)) {
                    mTVRoomName2.setText("无");
                } else {
                    mTVRoomName2.setText(rInfo2.name);
                    Util.setRoomStatus(mTVRoomPrice2, rInfo2, "not_sign_detail");
                }
            }
        }
        if (TextUtils.isEmpty(mOrder.viewOrder.phone)) {
            mTVCall.setVisibility(View.INVISIBLE);
        }
    }


    @Override
    public void onClick(View v) {
        if (v == mTVCall) {
            if (TextUtils.isEmpty(mOrder.viewOrder.phone)) {
                App.showToast("没有客户电话号码");
            } else {
                Uri uri = Uri.parse("tel:" + mOrder.viewOrder.phone);
                Intent intent = new Intent(Intent.ACTION_DIAL, uri);
                startActivity(intent);
            }
        }
    }
}
